package com.tucy.logistics.common.result;

/**
 * author: tcy
 * createDate: 2022/10/9
 * description:
 */

import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import java.util.Date;


@RestController
@ControllerAdvice
@Slf4j
public class ServiceExceptionAdvice {

    @ResponseBody
    @ExceptionHandler({ServiceException.class})
    public Result<Object> execute(ServiceException e){
        log.info("业务异常:code={},message={}",e.getCode(),e.getMessage());
        Result<Object> resultVo = new Result<>();
        resultVo.setCode(e.getCode());
        resultVo.setMessage(e.getMessage());
        resultVo.setData("服务器请求异常");
        resultVo.setData(new Date());
        return resultVo;
    }
}
